#include"Dictionary.hpp"
#include"DictServer.hpp"
#include<iostream>
#include<memory>

void Usage(std::string proc)
{
    std::cerr << "Usage:" << proc << " localport" << std::endl;
}

int main(int argc , char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    EnableConsoleLogStrategy();
    uint16_t port = std::stoi(argv[1]);//端口

    Dictionary dict("./dict.txt");

    //智能指针
    std::unique_ptr<DictServer> usvr = std::make_unique<DictServer>(port, [&dict](const std::
            string& word , const std::string& whoip , const uint16_t whoport)->std::string{
                return dict.Translate(word , whoip , whoport);
            });
    // std::cout<<1<<std::endl;
    usvr->Init();
    // std::cout<<2<<std::endl;
    usvr->Start();

    return 0;

}